package com.example.demo.controller;

import com.example.demo.base.ReqParamBody;
import com.example.demo.base.WebResult;
import com.example.demo.service.UserService;
import com.example.demo.vo.UserAddVO;
import com.example.demo.vo.UserPageVO;
import com.example.demo.vo.UserUpdateVO;
import com.example.demo.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 用户管理
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 新增用户
     */
    @PostMapping("/user/add")
    public WebResult addUser(@Valid @RequestBody ReqParamBody<UserAddVO> paramBody) {
        return userService.addUser(paramBody.getData());
    }

    /**
     * 修改用户
     */
    @PostMapping("/user/update")
    public WebResult updateUser(@Valid @RequestBody ReqParamBody<UserUpdateVO> paramBody) {
        return userService.updateUser(paramBody.getData());
    }

    /**
     * 查询用户列表
     */
    @PostMapping("/user/list")
    public WebResult listUser(@Valid @RequestBody ReqParamBody<UserVO> paramBody) {
        return userService.listUser(paramBody.getData());
    }

    /**
     * 查询用户列表-分页
     */
    @PostMapping("/user/page")
    public WebResult pageUser(@Valid @RequestBody ReqParamBody<UserPageVO> paramBody) {
        return userService.pageUser(paramBody.getData());
    }

    /**
     * 删除用户
     */
    @PostMapping("/user/delete/{id}")
    public WebResult deleteUser(@PathVariable Long id) {
        return WebResult.ok(userService.deleteUserById(id));
    }



}
